package data

import (
	"github.com/google/wire"
	"shop-demo/app/order/service/internal/conf"
	"shop-demo/app/order/service/internal/data/ent"
)

var ProviderSet = wire.NewSet(NewEntClient, NewData, NewOrderRepo)

type Data struct {
	db *ent.Client
}

func NewEntClient(data *conf.Data) *ent.Client {
	open, err := ent.Open(data.Database.Driver, data.Database.Source)
	if err != nil {
		panic(err)
	}
	return open
}

func NewData(c *ent.Client) (*Data, func()) {
	return &Data{
			db: c,
		}, func() {
			err := c.Close()
			if err != nil {
				panic(err)
			}
		}
}
